//
//  MideaProtocol.h
//  midea
//
//  Created by liujian on 14-5-21.
//  Copyright (c) 2014年 keane. All rights reserved.
//

/*
 *  usage:
 *  1. 控制/查询指令发送
 *  MideaProtocol* protocal = [[MideaProtocol alloc] init] ;
 *  [protocol setMessageMark:messageID];    //4个字节的消息ID，由应用自行产生，保证每次唯一
 *  [protocol setMessageTypeMark:0x0020];   //0020表示数据透传指令
 *  [protocol setTerminalID:_appliancesID]; //设置设备ID，该ID从设备列表接口获取
 *  [protocol setMessageArray:body];        //消息体数组
 *  NSData *sendData = [[NSData alloc] initWithBytes:[protocal getByteStream] length:[protocal getByteStreamLength]];   //把这个Data数据转换为10进制数组通过http服务器透传接口发出即可
 *
 *  2. 指令解析
 *  MideaProtocol *protocol = [[MideaProtocol alloc] initWithNSData:data];
 *  protocol.terminalID //获取设备ID
 *
 */

#import <Foundation/Foundation.h>

typedef enum protcolType
{
    PROTCOL_GET_DEVICE_SN = 0,
    PROTCOL_GET_DEVICE_MODEL,       // A0
    PROTCOL_SET_DEVICE_ID,
    PROTCOL_FIND_WIFI_LIST,
    PROTCOL_SET_DEVICE_WIFI_SSID_CONFIG,
    PROTCOL_SET_DEVICE_WIFI_NET_CONFIG,
    PROTCOL_SET_DEVICE_WIFI_STATUS,
    PROTCOL_FIND_TERMINAL,
    PROTCOL_KAI_JI_TEST
}ProtocolType;

@interface MideaProtocol : NSObject

@property (nonatomic)int16_t protocolHead;
@property (nonatomic)int8_t protocolVer;
@property (nonatomic)int8_t miMark; //should be 4 bit
@property (nonatomic)int8_t signMark;   //should be 4 bit
@property (nonatomic)int16_t messageLen;
@property (nonatomic)int16_t messageTypeMark;
@property (nonatomic)int32_t messageMark;
@property (nonatomic)int64_t timeStamp;
@property (nonatomic)int64_t terminalID;    //设备ID，should be 48 bit
@property (nonatomic)int16_t timeOut;
@property (nonatomic)int64_t appliancesID;  //没有用到，should be 48 bit
@property (nonatomic)int16_t messageCheck;
@property (nonatomic)int8_t messageDirection;   //should be 1 bit
@property (nonatomic)int8_t responseMark; //should be 1 bit
@property (nonatomic)int8_t compressMark; //should be 1 bit

@property (nonatomic)int8_t nullBit1; //should be 5 bit
@property (nonatomic)int32_t nullBit2; //should be 24 bit

@property (nonatomic,strong)NSMutableArray *messageArray; //every is 8 bit //for PlugIn
@property (nonatomic)int16_t messageSign;//should 16字节

- (void)setProtocolWithType:(ProtocolType)type withDic:(NSDictionary*)dc;
- (unsigned char*)getByteStream;
- (NSInteger)getByteStreamLength;

//初始化方法
- (id)initWithNSData:(NSData*)data;

@end
